<template>
<view>
<!-- 外卖模式的点单 --> 

<view class="waimaiContainer">
<!--分享  -->
  <!-- <view class='share_shop' style='background:{{setting.platformSetting.secondColor}};' catchtap='shareShop'>
    <text class='share_shop_title'>分享店铺</text>
  </view> -->
  <!-- 分享店铺海报 -->
  <canvas-shop-component :shopId="shopInfo.id" :ewmImgUrl="qrCodeUrl" v-if="posterShopState" @closePoaster="getChilrenPoster"></canvas-shop-component>
  <!-- 店铺头部样式 -->
  <view class="shop_top">
    <view class="shop_banner">
      <image mode="aspectFit" class="shop_banner_img" :src="shopInfo.shopBanner"></image>
    </view>
    <view class="shop_info">
      <view class="shop_info_top">
        <view class="shop_info_left">
          <text class="shop_info_name">{{shopInfo.shopName}}</text>
          <text class="shop_info_service">服务时间：{{shopInfo.serviceStartTime}}:00-{{shopInfo.serviceEndTime}}:00</text>
          <text class="shop_info_address">店铺地址：{{shopInfo.shopLocation}}</text>
        </view>
        <view class="shop_info_right">
          <image class="shop_info_logo" mode="aspectFit" :src="shopInfo.shopLogo"></image>
        </view>
      </view>
      <view class="shop_info_bottom">
        <view class="shop_btn_item" :data-phonenumber="shopInfo.kefuTelno" @click.stop="calling">
          <image class="shop_btn_img" src="https://image1.sansancloud.com/xianhua/2019_3/21/16/30/34_148.jpg?x-oss-process=style/preview_120"></image>
          <text class="shop_btn_text">联系商家</text>
        </view>
        <view class="shop_btn_item" @click.stop="clickCatch">
          <image class="shop_btn_img" src="https://image1.sansancloud.com/xianhua/2019_3/21/16/30/34_131.jpg?x-oss-process=style/preview_120"></image>
          <text class="shop_btn_text">导航</text>
        </view>
        <view class="shop_btn_item">
          <image class="shop_btn_img" src="https://image1.sansancloud.com/xianhua/2019_3/21/16/30/34_147.jpg?x-oss-process=style/preview_120"></image>
          <text class="shop_btn_text">收藏</text>
        </view>
        <view class="shop_btn_item" @click.stop="shareShop">
          <image class="shop_btn_img" src="https://image1.sansancloud.com/xianhua/2019_3/21/16/30/34_113.jpg?x-oss-process=style/preview_120"></image>
          <text class="shop_btn_text">分享</text>
        </view>
      </view>
    </view>
  </view>
  <!-- 场馆列表 -->
  <view class="venues_block" v-if="venuesTypeList&&venuesTypeList.length!=0">
    <view class="venues_title">
      <image class="venues_title_img" src="https://image1.sansancloud.com/xianhua/2019_6/28/19/49/53_128.jpg?x-oss-process=style/preview_120"></image>
      <text class="venues_title_text">预定</text>
    </view>
    <view class="venues_type_list">
      <scroll-view scroll-x class="venues_type_scroll_list" scroll-with-animation="true">
        <view :class="'venues_type_item ' + (selectVenuesData.venuesTypeData.index==index?'type_active':'')" :style="'background:' + (selectVenuesData.venuesTypeData.index==index?setting.platformSetting.defaultColor:'')" v-for="(data, index) in venuesTypeList" :key="index" :data-index="index" :data-info="data" data-type="venuesType" @click.stop="selectVenuesDataFun">
          <text class="venues_type_name">{{data.name}}</text>
        </view>
      </scroll-view>
    </view>
    <view class="days_list">
      <scroll-view scroll-x class="days_scroll_list" scroll-with-animation="true">
        <view class="days_item" v-for="(data, index) in nextSevenDaysList" :key="index" :style="(selectVenuesData.daysData.index==index?'border-bottom: 10rpx solid'+ setting.platformSetting.defaultColor:'') + ';color:' + (selectVenuesData.daysData.index==index?setting.platformSetting.defaultColor:'')" :data-info="data" :data-index="index" data-type="daysData" @click.stop="selectVenuesDataFun">
          <text class="days_item_week">{{data.weekData}}</text>
          <text class="days_item_data">{{data.oneDataStr}}</text>
        </view>
      </scroll-view>
    </view>
    <view class="venues_cell_list">
      <scroll-view scroll-x class="venues_cell_scroll_list" scroll-with-animation="true">
        <view class="venues_cell_item" v-for="(data, index) in venuesTypeList[selectVenuesData.venuesTypeData.index].venues" :key="index" :style="'border:1rpx solid ' + (selectVenuesData.venuesCelleData.index==index? setting.platformSetting.defaultColor:'#ccc') + ';background:' + (selectVenuesData.venuesCelleData.index==index? setting.platformSetting.secondColor:'#fff')" :data-info="data" :data-index="index" data-type="venuesCell" @click.stop="selectVenuesDataFun">
          <text class="venues_cell_item_name">{{data.name}}({{data.stock}}个)</text>
        </view>
      </scroll-view>
    </view>
    <view class="venues_cell_detail">
      <view class="venues_cell_detail_left">
        <view class="venues_cell_detail_info">
          <text class="venues_cell_detail_time">{{selectVenuesData.venuesCelleData.data.startTimeStr}}-{{selectVenuesData.venuesCelleData.data.endTimeStr}}</text>
          <text class="venues_cell_detail_text">任选时间段</text>
        </view>
        <view class="venues_cell_detail_price">
          <text class="venues_cell_detail_price_text" :style="'color:' + setting.platformSetting.defaultColor">￥{{selectVenuesData.venuesCelleData.data.price}}</text>
          <text class="venues_cell_detail_price_unit">起</text>
          <text class="venues_cell_detail_price_unit" v-if="selectVenuesData.venuesCelleData.data.unitType==1">（{{selectVenuesData.venuesCelleData.data.unitLength}}分钟）</text>
          <text class="venues_cell_detail_price_unit" v-if="selectVenuesData.venuesCelleData.data.unitType==2">（{{selectVenuesData.venuesCelleData.data.unitLength}}天）</text>
        </view>
      </view>
      <view class="venues_cell_detail_right">
        <text class="venues_cell_detail_right_text" @click.stop="scheduledVenuesFun" :style="'background:' + setting.platformSetting.defaultColor">预定</text>
      </view>
    </view>
  </view>
  <!-- 场馆预定 -->
<view class="zhezhao" v-if="venuesDateCellsState" @click.stop="hiddenZheZhao"></view>
<view class="venues_date_cells_block" v-if="venuesDateCellsState">
  <view class="venues_date_cells_title">
    <text class="venues_date_cells_name">{{venuesCellList.venues.name}}（{{venuesCellList.monthDay}}）</text>
  </view>
  <view class="venues_date_cells_list">
    <view class="venues_date_cells_item" v-for="(data, index) in venuesCellList.cells" :key="index" :data-type="(data.state?'cancel':'select')" :data-index="index" :data-info="data" :data-startSecond="data.startTimeSeconds" @click.stop="data.status!=1?'':'selecVenuesCellItemFun'" :style="'border: 1rpx solid ' + (data.state?setting.platformSetting.defaultColor:'#ccc') + ';background:' + (data.state?setting.platformSetting.defaultColor+'22':'#fff')">
      <text class="venues_date_cells_time" :style="'color:' + (data.status!=1?'#999':'')">{{data.startTimeStr}}</text>
      <text class="venues_date_cells_price" :style="'color:' + (data.status!=1?'#999':setting.platformSetting.defaultColor)">￥{{data.cellPrice}}</text>
      <text class="cell_tag_bg" v-if="data.cellTag" :style="'border-top: 30px solid ' + (data.status!=1?'#999':setting.platformSetting.defaultColor) + ';'"></text>
      <text class="cell_tag_text" v-if="data.cellTag">{{data.cellTag}}</text>
    </view>
  </view>
  <view class="have_venues_date_cells_title">
    <text>已选场次</text>
  </view>
  <view class="have_venues_date_cells_list" v-if="haveVenuesDateCellsList.length!=0">
  <!-- haveVenuesDateCellsList -->
    <view class="have_venues_date_cells_item" v-for="(data, index) in haveVenuesDateCellsList" :key="index" :style="'background:' + setting.platformSetting.defaultColor">
      <text class="have_venues_date_cells_time">{{data.info.startTimeStr}}-{{data.info.endTimeStr}}</text>
      <text class="have_venues_date_cells_price">￥{{data.info.cellPrice}}</text>
      <text class="circular"></text>
    </view>
  </view>
  <view class="no_have_venues_date_cells" v-else>暂无选择的场次</view>
  <view class="submit_data" :style="'background:' + setting.platformSetting.defaultColor" @click.stop="confirmReserve">
    <text class="all_price">￥{{allPrice}}</text>
    <text class="submit_data_text">确认预定</text>
  </view>
</view>
  <!-- 首页组件-私有产品详情装饰-->
<!-- <component-customPage :receiveData="sendShopData" v-if="componentState||componentIndexState"></component-customPage> -->
  <view class="product_info" v-else>
    <!-- 左边的导航 -->   
    <scroll-view scroll-y class="leftScrollType">
      <view :class="(allPro?'activeTypeItem':'TypeItem')" data-type="all" @tap="bindTypeItem" data-index="0">全部</view>  
      <view v-for="(type, index) in shopInfo.shopTypes" :key="index" :data-type="type" :data-index="index" @tap="bindTypeItem" :class="(type.active?'activeTypeItem':'TypeItem')">
          <!-- <block wx:if='{{!!type.typeIcon}}'>
            <image class='TypeItem_iamge' mode='aspectFit' src='{{type.typeIcon}}'></image>
          </block>
          <block wx:else></block> -->
          <text>{{type.typeName}}</text>
          <block v-if="type.hasInCartCount > 0">
            <view class="countNumTag countNumInLeft">{{type.hasInCartCount}}</view>
          </block>
          </view>
        <view class="ToOrderView_container">
          <block v-if="pushItem.length > 0">
            <view class="ToOrderView ToOrderView1" @tap="toMy" :style="'background:' + setting.platformSetting.defaultColor + ';'">
              <image mode="aspectFill" src="https://image1.sansancloud.com/xianhua/2019_12/16/15/54/40_186.jpg?x-oss-process=style/preview_120"></image>
              <text>我的</text>
            </view>
          </block>
          <block v-else>
          <view class="ToOrderView ToOrderView2" @tap="toMy" :style="'background:' + setting.platformSetting.defaultColor + ';'">
            <image mode="aspectFill" src="https://image1.sansancloud.com/xianhua/2019_12/16/15/54/40_186.jpg?x-oss-process=style/preview_120"></image>
            <text>我的</text>
          </view>
        </block>
        </view>
        
        <view class="bottomHeight"></view>
    </scroll-view>

    <!-- 右边的商品列表 -->
    <scroll-view scroll-y @scrolltolower="onReachBottom2" class="RightProductContainer">
      <view v-if="!shopProList" class="none">
        <image mode="widthFix" src="../../static/icons/no-product.png"></image>
        <text>没有相关商品</text>
      </view>
      <view class="productItem" v-for="(result, index) in shopProList" :key="index" :data-info="result" @tap="toProductDetail">
          <view class="productItemImage">
            <image mode="aspectFill" :src="result.imagePath + '?x-oss-process=style/preview'"></image>
          </view>
          <view class="productInfo">
            <view class="productInfo_name">{{result.name}}</view>
            <view class="productInfo_decribe">
              <text class="small_decribe">月售100件|好评99.9%</text>
              <text class="productInfo_promotionName" v-if="result.promotionName">{{result.promotionName}}</text>
            </view>
            <view class="productInfo_Price">

              <view>￥<text class="PRICE">{{result.price}}</text> </view>
              <view class="productInfo_Nums">
                <block v-if="!result.measureItem">
                  <block v-if="result.inCarCount>0">
                    <image src="https://image1.sansancloud.com/xianhua/2019_12/16/15/55/32_567.jpg?x-oss-process=style/preview_120" :data-id="index" @click.stop="subNum"></image>
                    <text class="font1">{{result.inCarCount}}</text>
                  </block>
                  <image src="https://image1.sansancloud.com/xianhua/2019_12/16/15/55/32_666.jpg?x-oss-process=style/preview_120" :data-id="index" @click.stop="addNum"></image>
                </block>
                <block v-else>
                  <block v-if="result.inCarCount>0">
                    <view class="PRICE"> {{result.inCarCount}}</view>
                </block>
                  <view class="choose_measureItem" :data-id="index" @click.stop="chooseMeasureItem">选规格</view>
                  </block>
              </view>

            </view>
          </view>
      </view>
      <view class="bottomHeight"></view>
    </scroll-view>
  </view>
  <!-- 首页组件-公共产品详情装饰-->
  <!-- <component-customPage :receiveData="sendIndexData"></component-customPage> -->
</view>

  <block v-if="pushItem.length > 0">
  <view class="bottomCartContainer" :style="'background:' + setting.platformSetting.defaultColor + ';'">
    <view class="cartInfo" @tap="showZheshao">
       <view class="imageCartContainer flexCenter">
         <image src="https://image1.sansancloud.com/xianhua/2019_12/16/15/56/3_253.jpg?x-oss-process=style/preview_120"></image>
         <view class="countCartNum">{{countGood}}</view>
       </view>
       <view class="Price">￥<text class="PRICE">{{countPrice}}</text></view>
    </view>
    <view class="sureButn" @tap="createOrder">选好了</view>
  </view>
  </block>

<view v-if="pushItem.length > 0" class="waimai_cart_container_forTap"> 
    <view class="Tap_cart">
      <block v-if="!showType"><view class="Tap_cart_v1" :style="'background:' + setting.platformSetting.defaultColor + ';'" @tap="showZheshao">^</view></block>
      <block v-else><view class="Tap_cart_v2" @tap="showZheshao">v</view> </block>
     </view>
  <scroll-view scroll-y class="waimai_cart_container" :animation="animationData">
    <view class="waimai_cart_item" v-for="(cartI, index) in pushItem" :key="index">
        <view class="waimai_cart_item_info">
          <view class="waimai_cart_item_info_name">{{cartI.name}}</view>
          <block v-if="!!cartI.measureCartensian">
          <view class="waimai_cart_item_info_measureCartensian">
            <view v-for="(mesure, index2) in cartI.measureCartensian.measurements" :key="index2">{{mesure.measureName}}</view>
          </view>
          </block>
          <view class="waimai_cart_item_info_price">
            ￥<text class="waimai_cart_item_info_price2">{{cartI.price}}</text>
          </view>
        </view>
        <view class="waimai_cart_item_nums">
                <image src="https://image1.sansancloud.com/xianhua/2019_12/16/15/55/32_567.jpg?x-oss-process=style/preview_120" :data-id="index" @click.stop="subCartNum"></image>
                <text class="font1">{{cartI.count_offline}}</text>
            
              <image src="https://image1.sansancloud.com/xianhua/2019_12/16/15/55/32_666.jpg?x-oss-process=style/preview_120" :data-id="index" @click.stop="addCartNum"></image>
        </view>
    </view>
  </scroll-view>
</view>

<view class="zhezhao" v-if="showType" @tap="closeZhezhao"></view>


<!-- 规格 -->
  <view v-if="showGuigeType" class="measureItemsContainer">
    <view class="measureItemsCard">
      <view class="cardHead">
        <view class="cardHeadTip"><view></view><view></view><view></view></view>
        <view class="cardHeadName">{{MeasureItem.name}}</view>
        <view class="closeCard" @tap="closeGuigeZhezhao">
         <icon type="clear" color="red" size="23"></icon>
        </view>
      </view>
      <view class="cardMid" v-for="(types, index) in MeasureItem.measureTypes" :key="index">
        <view class="cardMidName">{{types.name}}</view>
        <radio-group class="cardMidGuigeContainer" :name="types.name" @change="chooseMeasure">
          <label v-for="(Measure, i) in types.productAssignMeasure" :key="i" :data-index="index + '-' + i" @tap="radioChange">
            <view :class="(types.checkedMeasureItem == i? 'active':'')">{{Measure.measureName}}</view>
            <radio :checked="types.checkedMeasureItem == i" :value="Measure.measureTypeName + '-' + Measure.id" hidden="true"></radio>
          </label>
        </radio-group>
      </view>
     
      <view class="submitMeasure">
        <view class="submitMeasure_price">￥ <text class="PRICE">{{measurementJson.price}}</text></view>
        <view class="submitMeasure_addto" @tap="submitMeasure">加入购物车</view>
      </view>

    </view>
  </view>

<view class="zhezhao" v-if="showGuigeType"></view>
</view>
</template>

<script>
// import posteractive from "../../view/partials/canvas_shop/index";
// import componentCustompage from "../../view/partials/custom_page/index";

export default {
  data() {
    return {
      animationData: {},
      setting: null,
      // setting   
      productData: [],
      // 商品数据 
      sysWidth: 320,
      //图片大小
      tab: '',

      /* 显示或影藏 */
      showType: false,
      show0: false,
      show1: false,
      show2: false,
      shopInfo: null,
      shopProList: null,
      proTypeState: false,
      allPro: true,
      componentState: true,
      componentIndexState: true,
      topName: {
        SearchProductName: "" //头部搜索的

      },
      nextSevenDaysList: [],
      venuesTypeList: [],
      venuesCellList: [],
      selectVenuesData: {
        venuesTypeData: {
          index: 0,
          data: null
        },
        daysData: {
          index: 0,
          data: null
        },
        venuesCelleData: {
          index: 0,
          data: null
        }
      },
      venuesTypeData: {
        index: 0,
        data: null
      },
      daysData: {
        index: 0,
        data: null
      },
      venuesCelleData: {
        index: 0,
        data: null
      },
      venuesDateCellsState: false,
      haveVenuesDateCellsList: [],
      allPrice: 0,
      focusTypeItem: null,
      bindProductTypeIndex: null,
      ProductshowWay: 1,
      // ProductshowWay列表显示方法 
      posterShopState: false,
      typeSearch: '',
      // typeSearch的字体 
      canRefresh: true,

      /* 购物车 */
      cart: [],
      pushItem: [],
      countGood: 0,
      countPrice: 0,
      //规格
      showGuigeType: false,
      checkedMeasureItem: 0,
      MeasureItem: null,
      measurementJson: {
        price: 0
      } //规格价格
      ,

      /* 全部参数 */
      params: {
        categoryId: "",
        platformNo: "",
        belongShop: "",
        typeBelongShop: "",
        page: 1,
        showType: "",
        showColumn: "",
        productName: "",
        startPrice: "",
        endPrice: "",
        orderType: "",
        saleTypeId: "",
        promotionId: "",
        shopProductType: "",
        needCarCount: 1
      },

      /* 创建订单 */
      postCarItemJson: {
        shopId: '',
        orderType: ''
      },
      listPage: {
        page: 1,
        pageSize: 0,
        totalSize: 0,
        curpage: 1
      },
      qrCodeUrl: "",
      shopCount: "",
      sendIndexData: "",
      sendShopData: ""
    };
  },
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log("===options=====", options);
    var that = this;

    if (!getApp().globalData.setting) {
      console.log('-------------hasNoneSetting-----------');
      getApp().globalData.getSetting(that);
    } else {
      console.log('-------------hasSetting-----------');
      that.setData({
        setting: getApp().globalData.setting
      });
      console.log(that.setting);
    }

    that.params.belongShop = options.addShopId;
    let belongShopId = 'belongShopId_' + options.addShopId;
    that.getParac("index");
    that.getParac();

    if (getApp().globalData.cart_offline[belongShopId]) {
      that.setData({
        pushItem: getApp().globalData.cart_offline[belongShopId]
      });
    } else {
      that.setData({
        pushItem: []
      });
    }

    console.log("app.cart_offline", getApp().globalData.cart_offline);
    that.params.shopProductType = 0;
    that.getShopTypeData(options);
    that.getShopVenuesTypeData(options);
    let sendIndexData = JSON.stringify({
      title: 'noTitle',
      url: "shop",
      params: {
        pageObjectId: that.params.belongShop,
        pageObjectType: 9
      }
    });
    that.setData({
      sendIndexData: sendIndexData
    });
    let sendShopData = JSON.stringify({
      title: 'noTitle',
      url: "shop_" + that.params.belongShop
    });
    that.setData({
      sendShopData: sendShopData
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    // this.listPage.page = 1
    // this.params.page = 1
    // this.getData(this.params, 2)
    wx.showNavigationBarLoading();
    wx.hideNavigationBarLoading(); //完成停止加载

    wx.stopPullDownRefresh(); //停止下拉刷新
  },

  /* 分享 */
  onShareAppMessage: function (res) {
    // 分享页面
    let userId = ""; //console.log("app.loginUser.platformUser", app.loginUser.platformUser.id)

    if (getApp().globalData.loginUser && getApp().globalData.loginUser.platformUser) {
      userId = 'MINI_PLATFORM_USER_ID_' + getApp().globalData.loginUser.platformUser.id;
    } // console.log("app.loginUser.platformUser", app.loginUser.platformUser.id)
    // path=pageTab%2findex%2findex%3fAPPLY_SERVER_CHANNEL_CODE%3d'


    let postParam = {};
    postParam.belongShop = this.params.belongShop;
    postParam.shopName = this.shopInfo.shopName;
    postParam.scene = userId;
    console.log("分享页面", postParam);
    return getApp().globalData.shareForFx2(getApp().globalData.miniIndexPage, postParam.shopName, postParam);
  },
  methods: {
    getChilrenPoster(e) {
      let that = this;
      that.setData({
        posterShopState: false
      });
    },

    shareShop: function () {
      let that = this;
      this.getQrCode();
    },
    // 获取二维码
    getQrCode: function () {
      let userId = "";
      var that = this;
      if (getApp().globalData.loginUser && getApp().globalData.loginUser.platformUser) {
        userId = 'MINI_PLATFORM_USER_ID_' + getApp().globalData.loginUser.platformUser.id;
      } // path=pageTab%2findex%2findex%3fAPPLY_SERVER_CHANNEL_CODE%3d'
      let postParam = {};
      postParam.SHARE_PRODUCT_DETAIL_PAGE = this.params.belongShop;
      postParam.scene = userId; // 上面是需要的参数下面的url

      var customIndex = getApp().globalData.AddClientUrl("/super_shop_manager_get_mini_code.html?mini=1&path=pageTab%2findex%2findex%3fENTER_SHOP%3d" + this.params.belongShop + "%26scene%3d" + userId, postParam, 'get', '1');
      var result = customIndex.url.split("?");
      customIndex.url = result[0] + "?" + result[1];
      console.log("customIndex", customIndex.url, result[0]);
      that.setData({
        qrCodeUrl: customIndex.url,
        posterShopState: true
      });
      console.log();
    },
    setAppCart: function () {
      let belongShopId = 'belongShopId_' + this.params.belongShop;
      getApp().globalData.cart_offline[belongShopId] = this.pushItem;
    },
    // 定位
    clickCatch: function (e) {
      console.log(this.shopInfo);
      let latitude = this.shopInfo.latitude;
      let longitude = this.shopInfo.longitude;
      let name = this.shopInfo.shopName;
      let address = this.shopInfo.shopLocation;
      wx.openLocation({
        latitude: latitude,
        longitude: longitude,
        scale: 12,
        name: name,
        address: address
      });
    },
    calling: function (e) {
      console.log('====e===', e);
      let phoneNumber = e.currentTarget.dataset.phonenumber || "";
      getApp().globalData.calling(phoneNumber);
    },
    //跳转到订单页面
    toOrderPage: function (e) {
      let linkUrl = e.currentTarget.dataset.link;
      getApp().globalData.linkEvent(linkUrl);
    },
    toMy: function (e) {
      getApp().globalData.toMy();
    },

    /* 点击遮罩层 */
    closeZhezhao: function () {
      this.getShopListData(this.params, 2);
      this.setData({
        showType: false
      });
      let animation = wx.createAnimation({
        duration: 400,
        timingFunction: 'ease-out'
      });
      animation.height(0).step();
      this.setData({
        animationData: animation.export()
      });
    },
    showZheshao: function () {
      this.setData({
        pushItem: this.pushItem
      });
      this.setData({
        showType: !this.showType
      });
      let showType2 = this.showType;
      let animation = wx.createAnimation({
        duration: 400,
        timingFunction: 'ease-in-out'
      });

      if (showType2) {
        animation.height(250).step();
      } else {
        animation.height(0).step();
      }

      this.setData({
        animationData: animation.export()
      });
    },

    /* 点击分类大项 */
    bindTypeItem: function (event) {
      this.listPage.page = 1;
      this.params.page = 1;
      console.log('======1======', event.currentTarget.dataset);

      if (event.currentTarget.dataset.type === 'all') {
        console.log("-=======this.data.shopInfo=========", this.shopInfo);
        let belongShop = this.shopInfo.id;
        let shopProductType = event.currentTarget.dataset.index;
        let param = Object.assign({}, param, {
          belongShop: belongShop,
          shopProductType: shopProductType
        });
        this.setData({
          allPro: true
        });

        for (let i = 0; i < this.shopInfo.shopTypes.length; i++) {
          this.shopInfo.shopTypes[i].active = false;
        }

        this.setData({
          shopInfo: this.shopInfo
        });
        this.getShopListData(param, 2);
      } else {
        let belongShop = event.currentTarget.dataset.type.belongShopId;
        let shopProductType = event.currentTarget.dataset.type.id;
        let param = Object.assign({}, param, {
          belongShop: belongShop,
          shopProductType: shopProductType
        });
        this.setData({
          allPro: false
        });

        for (let i = 0; i < this.shopInfo.shopTypes.length; i++) {
          if (this.shopInfo.shopTypes[i].id == event.currentTarget.dataset.type.id) {
            this.shopInfo.shopTypes[i].active = true;
          } else {
            this.shopInfo.shopTypes[i].active = false;
          }
        }

        console.log("this.data.shopInfo.shopTypes", this.shopInfo.shopTypes);
        this.setData({
          shopInfo: this.shopInfo
        });
        this.getShopListData(param, 2);
      }
    },
    ChangeParam: function (params) {
      var returnParam = "";

      for (let i in params) {
        returnParam += "&" + i + "=" + params[i];
      }

      console.log(returnParam);
      return returnParam;
    },

    /* 拿出价格和购物车里面的东西 */
    showPrice: function () {
      var cartDataItem = this.cart[0].carItems;
      var pushItem = [];
      /*  var countGood = 0
       var countPrice = 0 */

      for (let i = 0; i < cartDataItem.length; i++) {
        pushItem.push(cartDataItem[i]);
      }
      /*  for (let i = 0; i < pushItem.length; i++) {
         countGood += parseInt(pushItem[i].count)
         countPrice += parseInt(pushItem[i].count) * pushItem[i].carItemPrice
       } */


      this.setData({
        pushItem: pushItem
        /*     countGood: countGood,
            countPrice: countPrice */

      });
      /* console.log(pushItem)
      console.log(countGood)
      console.log(countPrice) */
    },

    /* 产品的加减 */
    subNum: function (event) {
      let productData = this.shopProList;
      let index = event.currentTarget.dataset.id;
      let focusProduct = productData[index];
      console.log(focusProduct);
      --focusProduct.inCarCount;
      this.setData({
        shopProList: productData
      });
      this.dellProduct(focusProduct, 'sub');
    },
    addNum: function (event) {
      let productData = this.shopProList;
      let index = event.currentTarget.dataset.id;
      let focusProduct = productData[index];
      console.log(focusProduct);
      ++focusProduct.inCarCount; //添加购买数量

      this.setData({
        shopProList: productData
      });
      this.dellProduct(focusProduct, 'add');
    },
    //删除函数
    delectFromPushItem: function (index) {
      let pushItem = this.pushItem;
      pushItem.splice(index, 1);
      this.setData({
        pushItem: this.pushItem
      });
    },
    delectFromProduct: function (product) {
      let productData = this.shopProList;

      for (let i = 0; i < productData.length; i++) {
        if (product.id == productData[i].id) {
          productData[i].inCarCount = 0;
        }
      }

      this.setData({
        shopProList: productData
      });
    },
    dellProduct: function (focusProduct, Ptype, measureId) {
      console.log('========0=======', focusProduct);
      let productData = this.shopProList;
      let pushItem = this.pushItem;

      if (!measureId) {
        console.log('=====1=====');
        measureId = 0;
      }

      if (!!measureId) {
        console.log('=====2=====');

        if (Ptype == 'sub') {
          var result = this.checkSub(focusProduct, measureId);
          console.log(result);

          if (result.ifOne) {
            this.delectFromPushItem(result.index);
            this.delectFromProduct(focusProduct);
          } else {
            --pushItem[result.index].count_offline;
          }
        }

        if (Ptype == 'add') {
          //检查是否在购物车里面数量为1
          let result = this.checkAdd(focusProduct, measureId);

          if (result.have) {
            //如果在那么就给他的数量加1
            ++pushItem[result.index].count_offline;
          } else {
            focusProduct.count_offline = 1;
            pushItem.push(focusProduct);
          }
        }

        console.log(pushItem);
        this.getPriceAndCount();
        this.setData({
          pushItem: pushItem
        });
      } else {
        console.log('=====3=====');

        if (Ptype == 'sub') {
          console.log('=====sub====='); //检查是否在购物车里面

          var result = this.checkSub(focusProduct);
          console.log(result);

          if (result.ifOne) {
            //如果在那么就给他删了
            //他的index有了
            this.delectFromPushItem(result.index);
          } else {
            --pushItem[result.index].count_offline;
          }
        }

        if (Ptype == 'add') {
          console.log('=====add====='); //检查是否在购物车里面数量为1

          var result = this.checkAdd(focusProduct);

          if (result.have) {
            //如果在那么就给他的数量加1
            ++pushItem[result.index].count_offline;
          } else {
            focusProduct.count_offline = 1;
            pushItem.push(focusProduct);
          }
        }
      }

      console.log('===pushItem====', pushItem);
      this.getPriceAndCount();
      this.setData({
        pushItem: pushItem
      });
      this.showAnimation();
      this.setAppCart();
    },
    showAnimation: function () {
      let animation = wx.createAnimation({
        duration: 300,
        timingFunction: 'ease-in-out'
      });
      animation.scale(1.5).step();
      animation.scale(1).step();
      this.setData({
        shopCount: animation.export()
      });
    },
    //做一个cart数据集和一个产品的数据集，
    //然后相互校对，一般是addNum时校对购物车里面的addCarNum时校对产品数据
    //所以cart的数据集很有必要
    //addNum的时候加入
    checkAdd: function (product, MeasureId) {
      console.log('===this.data.pushItem======', this.pushItem);
      let pushItem = this.pushItem;
      let result = {
        have: 0,
        index: -1
      };

      if (!pushItem) {
        let result = {
          have: 0,
          index: 0
        };
      }

      if (!MeasureId) {
        MeasureId = 0;
      }

      if (!!MeasureId) {
        for (let i = 0; i < pushItem.length; i++) {
          if (product.id == pushItem[i].id) {
            if (MeasureId == pushItem[i].measureCartensian.id) {
              result.have = 1;
              result.index = i;
            }
          }
        }
      } else {
        for (let i = 0; i < pushItem.length; i++) {
          if (product.id == pushItem[i].id) {
            result.have = 1;
            result.index = i;
          }
        }
      }

      return result;
    },
    checkSub: function (product, MeasureId) {
      let pushItem = this.pushItem;
      let result = {
        ifOne: 0,
        index: -1
      };

      if (!MeasureId) {
        MeasureId = 0;
      }

      if (!!MeasureId) {
        for (let i = 0; i < pushItem.length; i++) {
          if (product.id == pushItem[i].id) {
            console.log('----product  相等---------');

            if (pushItem[i].count_offline == 1) {
              if (MeasureId == pushItem[i].measureCartensian.id) {
                console.log('----measureCartensian  相等---------');
                result.ifOne = 1;
                result.index = i;
              }
            } else {
              if (MeasureId == pushItem[i].measureCartensian.id) {
                console.log('----measureCartensian  相等---------');
                result.ifOne = 0;
                result.index = i;
              }
            }
          }
        }
      } else {
        for (let i = 0; i < pushItem.length; i++) {
          if (product.id == pushItem[i].id) {
            if (pushItem[i].count_offline == 1) {
              console.log('-----------1--------------');
              result.ifOne = 1;
              result.index = i;
            } else {
              result.ifOne = 0;
              result.index = i;
            }
          }
        }
      }

      return result;
    },

    /* 初始化Nums  用传值方式 */
    //计算价格和数量
    getPriceAndCount: function () {
      let pushItem = this.pushItem;
      let countPrice = 0;
      let countGood = 0;

      for (let i = 0; i < pushItem.length; i++) {
        countGood += pushItem[i].count_offline;
        countPrice += pushItem[i].count_offline * pushItem[i].price;
      }

      countPrice = countPrice.toFixed(2);
      this.setData({
        countGood: countGood,
        countPrice: countPrice
      });

      if (this.countGood == 0) {
        this.closeZhezhao();
      }
      /* 计算setting的type分类incart数量 */


      console.log('=====this.data.shopInfo.shopTypes=====', this.shopInfo.shopTypes);
      console.log('=====this.data.pushItem=====', this.pushItem);
      let categories = this.shopInfo.shopTypes;

      if (this.shopInfo.shopTypes) {
        for (let j = 0; j < categories.length; j++) {
          categories[j].hasInCartCount = 0;
        }

        for (let i = 0; i < pushItem.length; i++) {
          for (let j = 0; j < categories.length; j++) {
            if (pushItem[i].shopProductType == categories[j].id) {
              categories[j].hasInCartCount += pushItem[i].count_offline;
            }
          }
        }
      }

      console.log('=====this.data.shopInfo.shopTypes=====', this.shopInfo.shopTypes);
      this.setData({
        shopInfo: this.shopInfo
      });
    },
    //操作购物车
    dellCart: function (focusProduct, Ptype, measureId) {
      let productData = this.shopProList;
      let pushItem = this.pushItem;

      if (!measureId) {
        measureId = 0;
      }

      if (!!measureId) {
        if (Ptype == 'sub') {
          //检查是否在购物车里面
          var result = this.checkSub(focusProduct, measureId);
          console.log(result);

          if (result.ifOne) {
            //如果在那么就给他删了
            //他的index有了
            this.delectFromPushItem(result.index);
            this.delectFromProduct(focusProduct);
          } else {
            --pushItem[result.index].count_offline;
          }
        }

        if (Ptype == 'add') {
          //检查是否在购物车里面数量为1
          var result = this.checkAdd(focusProduct, measureId);

          if (result.have) {
            //如果在那么就给他的数量加1
            ++pushItem[result.index].count_offline;
          } else {
            focusProduct.count_offline = 1;
            pushItem.push(focusProduct);
          }
        }
      } else {
        if (Ptype == 'sub') {
          //检查是否在购物车里面
          var result = this.checkSub(focusProduct);
          console.log(result);

          if (result.ifOne) {
            //如果在那么就给他删了
            //他的index有了
            this.delectFromPushItem(result.index);
            this.delectFromProduct(focusProduct);
          } else {
            --pushItem[result.index].count_offline;
          }
        }

        if (Ptype == 'add') {
          //检查是否在购物车里面数量为1
          var result = this.checkAdd(focusProduct);

          if (result.have) {
            //如果在那么就给他的数量加1
            ++pushItem[result.index].count_offline;
          } else {
            focusProduct.count_offline = 1;
            pushItem.push(focusProduct);
          }
        }
      }

      console.log(pushItem);
      this.setCartInProduct();
      this.getPriceAndCount();
      this.setData({
        pushItem: pushItem
      });
    },

    /* 购物车的加减 */
    subCartNum: function (e) {
      var that = this;
      var pushItem = this.pushItem;
      var focusCartItem = null;
      var index = e.currentTarget.dataset.id;
      console.log(pushItem);
      focusCartItem = pushItem[index];

      if (!!focusCartItem.measureCartensian) {
        this.dellCart(focusCartItem, 'sub', focusCartItem.measureCartensian.id);
      } else {
        this.dellCart(focusCartItem, 'sub');
      }
    },
    addCartNum: function (e) {
      var that = this;
      var pushItem = this.pushItem;
      var focusCartItem = null;
      var index = e.currentTarget.dataset.id;
      focusCartItem = pushItem[index];

      if (!!focusCartItem.measureCartensian) {
        this.dellCart(focusCartItem, 'add', focusCartItem.measureCartensian.id);
      } else {
        this.dellCart(focusCartItem, 'add');
      }
    },

    /* 获取数据 */
    getShopTypeData: function (param) {
      //根据把param变成&a=1&b=2的模式
      var customIndex = getApp().globalData.AddClientUrl('/shop_detail_' + param.addShopId + '.html'); // wx.showLoading({
      //   title: 'loading'
      // })

      getApp().globalData.showToastLoading('loading', true);
      var that = this;
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log("=====shopdata======", res.data);
          let dataArr = res.data.result.shopInfo;

          if (!res.data.result.shopInfo) {
            that.setData({
              shopInfo: null
            });
          } else {
            that.setData({
              shopInfo: dataArr
            });
          }

          that.getShopListData(that.params, 2);
          wx.hideLoading();
        },
        fail: function (res) {
          console.log("fail");
          wx.hideLoading();
          getApp().globalData.loadFail();
        },
        complete: function () {
          that.setData({
            canRefresh: true
          });
        }
      });
    },

    /* 获取数据 */
    getShopListData: function (param, ifAdd) {
      if (!ifAdd) {
        ifAdd = 1;
      }

      console.log('====getShopListData.param======', param); //根据把param变成&a=1&b=2的模式

      var customIndex = getApp().globalData.AddClientUrl('/more_product_list.html', param); // wx.showLoading({
      //   title: 'loading'
      // })

      getApp().globalData.showToastLoading('loading', true);
      var that = this;
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log("=====shopListdata======", res.data);
          that.listPage.pageSize = res.data.pageSize;
          that.listPage.curPage = res.data.curPage;
          that.listPage.totalSize = res.data.totalSize;
          let dataArr = that.shopProList;

          if (ifAdd == 2) {
            dataArr = [];
          }

          if (!res.data.result || res.data.result.length == 0) {
            that.setData({
              shopProList: null
            });
          } else {
            if (dataArr == null) {
              dataArr = [];
            }

            dataArr = dataArr.concat(res.data.result);
            that.setData({
              shopProList: dataArr
            });
          }

          wx.hideLoading();
          that.setCartInProduct();
        },
        fail: function (res) {
          console.log("fail");
          wx.hideLoading();
          getApp().globalData.loadFail();
        },
        complete: function () {
          that.setData({
            canRefresh: true
          });
        }
      });
    },
    /* 确认预定场馆 */
    confirmReserve: function () {
      console.log("=====confirmReserve========");
      let that = this;
      let param = that.selectVenuesData;
      let startSeconds = [];
      let haveVenuesDateCellsList = that.haveVenuesDateCellsList;

      for (let i = 0; i < haveVenuesDateCellsList.length; i++) {
        startSeconds.push(haveVenuesDateCellsList[i].startSecond);
      }

      if (startSeconds.length == 0) {
        wx.showToast({
          title: '请选择场次!',
          image: '/wxcomponents/images/icons/tip.png',
          duration: 1000
        });
        return;
      }

      console.log("======startSeconds============", startSeconds);
      let params = {
        venuesId: param.venuesCelleData.data.id,
        venuesDateStr: param.daysData.data.oneData,
        startSeconds: startSeconds.join(',')
      };
      var customIndex = getApp().globalData.AddClientUrl('/create_venues_order.html', params, 'post');
      getApp().globalData.showToastLoading('loading', true);
      wx.request({
        url: customIndex.url,
        data: customIndex.params,
        header: getApp().globalData.headerPost,
        method: 'POST',
        success: function (res) {
          console.log("=====confirmReserve_res======", res.data);

          if (res.data.errcode == 0) {
            wx.navigateTo({
              url: '/pages/edit_order/index?orderNo=' + res.data.relateObj.orderNo
            });
          }

          wx.hideLoading();
        },
        fail: function (res) {
          console.log("fail");
          wx.hideLoading();
          getApp().globalData.loadFail();
        },
        complete: function () {}
      });
    },
    /* 选择场馆 */
    selecVenuesCellItemFun: function (e) {
      console.log("=====selecVenuesCellItemFun========", e);
      let that = this;
      let index = e.currentTarget.dataset.index;
      let info = e.currentTarget.dataset.info;
      let type = e.currentTarget.dataset.type;
      let startSecond = e.currentTarget.dataset.startsecond;
      let haveVenuesDateCellsList = that.haveVenuesDateCellsList;
      let allPrice = 0;
      let venuesCellList = that.venuesCellList;

      if (haveVenuesDateCellsList.length != 0) {
        console.log("已有选择场次");

        if (type == 'cancel') {
          console.log("取消场次");

          for (let i = 0; i < haveVenuesDateCellsList.length; i++) {
            if (haveVenuesDateCellsList[i].startSecond == startSecond) {
              haveVenuesDateCellsList.splice(i, 1);
              venuesCellList.cells[index].state = false;
            }
          }
        } else {
          console.log("选择场次");
          haveVenuesDateCellsList.splice(haveVenuesDateCellsList.length, 0, {
            startSecond: startSecond,
            info: info
          });
          venuesCellList.cells[index].state = true;
        }
      } else {
        console.log("第一次选择场次");
        haveVenuesDateCellsList.splice(haveVenuesDateCellsList.length, 0, {
          startSecond: startSecond,
          info: info
        });
        venuesCellList.cells[index].state = true;
      }

      for (let i = 0; i < haveVenuesDateCellsList.length; i++) {
        allPrice += haveVenuesDateCellsList[i].info.cellPrice;
      }

      console.log("=====haveVenuesDateCellsList========", haveVenuesDateCellsList);
      that.setData({
        haveVenuesDateCellsList: haveVenuesDateCellsList,
        venuesCellList: venuesCellList,
        allPrice: allPrice
      });
    },

    /* 预定场馆 */
    scheduledVenuesFun: function () {
      console.log("=====scheduledVenuesFun========");
      let that = this;
      that.setData({
        venuesDateCellsState: true
      });
    },
    hiddenZheZhao: function () {
      console.log("=====hiddenZheZhao========");
      let that = this;
      that.setData({
        venuesDateCellsState: false
      });
    },

    /* 获取场馆日期单元 */
    getVenuesDateCellsData: function (param) {
      console.log("=====getVenuesDateCellsData========", param);
      let params = {
        venuesId: param.venuesCelleData.data.id,
        venuesDateStr: param.daysData.data.oneData
      };
      var customIndex = getApp().globalData.AddClientUrl('/wx_get_venues_date_cells.html', params); // wx.showLoading({
      //   title: 'loading'
      // })

      getApp().globalData.showToastLoading('loading', true);
      var that = this;
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log("=====getVenuesDateCellsData======", res.data);

          if (res.data.errcode == 0) {
            let venuesCellList = res.data.relateObj[0];

            for (let i = 0; i < venuesCellList.cells.length; i++) {
              venuesCellList.cells[i].state = false;
            }

            that.setData({
              venuesCellList: venuesCellList
            });
            console.log("=====venuesCellList======", that.venuesCellList);
          }

          wx.hideLoading();
        },
        fail: function (res) {
          console.log("fail");
          wx.hideLoading();
          getApp().globalData.loadFail();
        },
        complete: function () {
          that.setData({
            canRefresh: true
          });
        }
      });
    },
    selectVenuesDataFun: function (e) {
      let that = this;
      console.log("====selectVenuesDataFun===", e);
      let selectVenuesData = that.selectVenuesData;
      let type = e.currentTarget.dataset.type;
      let index = e.currentTarget.dataset.index;
      let info = e.currentTarget.dataset.info;
      that.setData({
        haveVenuesDateCellsList: [],
        allPrice: 0
      });

      if (type == 'venuesType') {
        console.log("===========venuesType===============");
        selectVenuesData.venuesTypeData = {
          index: index,
          data: info
        };
        selectVenuesData.daysData = {
          index: 0,
          data: that.nextSevenDaysList[0]
        };

        if (that.venuesTypeList[index].venues.length != 0) {
          selectVenuesData.venuesCelleData = {
            index: 0,
            data: that.venuesTypeList[index].venues[0]
          };
          that.getVenuesDateCellsData(selectVenuesData);
        }
      } else if (type == 'daysData') {
        console.log("===========daysData===============");
        selectVenuesData.daysData = {
          index: index,
          data: info
        };

        if (that.venuesTypeList[selectVenuesData.venuesTypeData.index].venues.length != 0) {
          // selectVenuesData.venuesCelleData = { index: 0, data: that.data.venuesTypeList[selectVenuesData.venuesTypeData.index].venues[0] }
          that.getVenuesDateCellsData(selectVenuesData);
        }
      } else {
        console.log("===========venuesCell===============");
        selectVenuesData.venuesCelleData = {
          index: index,
          data: info
        };
        that.getVenuesDateCellsData(selectVenuesData);
      }

      that.setData({
        selectVenuesData: selectVenuesData
      });
      console.log("====selectVenuesDataFun===", e, selectVenuesData);
    },
    getNextSevenDays: function () {
      let that = this;
      let myDate = new Date();
      let curDayData = myDate.getDay();
      let curLocaleData = myDate.toLocaleDateString(); //获取当前日期

      console.log("====getNextSevenDays===", curDayData, curLocaleData);

      for (let i = 0; i < 10; i++) {
        console.log("=======", i + curDayData);
        let switchData;
        let oneData;

        if (i + curDayData > 6 && i + curDayData < 14) {
          switchData = i + curDayData - 7;
        } else if (i + curDayData >= 14) {
          switchData = i + curDayData - 14;
        } else {
          switchData = i + curDayData;
        }

        switch (switchData) {
          case 0:
            oneData = that.getOneDay(i);
            that.nextSevenDaysList.splice(that.nextSevenDaysList.length, 0, {
              weekData: i != 0 ? '周日' : '今天',
              oneData: oneData,
              oneDataStr: oneData.slice(5)
            });
            console.log("====getOneDay=====", i, that.getOneDay(i));
            console.log("===that.data.nextSevenDaysList===", that.nextSevenDaysList);
            break;

          case 1:
            oneData = that.getOneDay(i);
            that.nextSevenDaysList.splice(that.nextSevenDaysList.length, 0, {
              weekData: i != 0 ? '周一' : '今天',
              oneData: oneData,
              oneDataStr: oneData.slice(5)
            });
            console.log("====getOneDay=====", i, that.getOneDay(i));
            console.log("===that.data.nextSevenDaysList===", that.nextSevenDaysList);
            break;

          case 2:
            oneData = that.getOneDay(i);
            that.nextSevenDaysList.splice(that.nextSevenDaysList.length, 0, {
              weekData: i != 0 ? '周二' : '今天',
              oneData: oneData,
              oneDataStr: oneData.slice(5)
            });
            console.log("====getOneDay=====", i, that.getOneDay(i));
            console.log("===that.data.nextSevenDaysList===", that.nextSevenDaysList);
            break;

          case 3:
            oneData = that.getOneDay(i);
            that.nextSevenDaysList.splice(that.nextSevenDaysList.length, 0, {
              weekData: i != 0 ? '周三' : '今天',
              oneData: oneData,
              oneDataStr: oneData.slice(5)
            });
            console.log("====getOneDay=====", i, that.getOneDay(i));
            console.log("===that.data.nextSevenDaysList===", that.nextSevenDaysList);
            break;

          case 4:
            oneData = that.getOneDay(i);
            that.nextSevenDaysList.splice(that.nextSevenDaysList.length, 0, {
              weekData: i != 0 ? '周四' : '今天',
              oneData: oneData,
              oneDataStr: oneData.slice(5)
            });
            console.log("====getOneDay=====", i, that.getOneDay(i));
            console.log("===that.data.nextSevenDaysList===", that.nextSevenDaysList);
            break;

          case 5:
            let oneData = that.getOneDay(i);
            that.nextSevenDaysList.splice(that.nextSevenDaysList.length, 0, {
              weekData: i != 0 ? '周五' : '今天',
              oneData: oneData,
              oneDataStr: oneData.slice(5)
            });
            console.log("====getOneDay=====", i, that.getOneDay(i));
            console.log("===that.data.nextSevenDaysList===", that.nextSevenDaysList);
            break;

          case 6:
            oneData = that.getOneDay(i);
            that.nextSevenDaysList.splice(that.nextSevenDaysList.length, 0, {
              weekData: i != 0 ? '周六' : '今天',
              oneData: oneData,
              oneDataStr: oneData.slice(5)
            });
            console.log("====getOneDay=====", i, that.getOneDay(i));
            console.log("===that.data.nextSevenDaysList===", that.nextSevenDaysList);
            break;
        }
      }

      let selectVenuesData = that.selectVenuesData;
      selectVenuesData.daysData = {
        index: 0,
        data: that.nextSevenDaysList[0]
      };
      that.setData({
        selectVenuesData: selectVenuesData
      });
      that.setData({
        nextSevenDaysList: that.nextSevenDaysList
      });
      that.getVenuesDateCellsData(selectVenuesData);
    },
    getOneDay: function (day) {
      var dd = new Date();
      dd.setDate(dd.getDate() + day); //获取AddDayCount天后的日期 

      var y = dd.getFullYear();
      var m = dd.getMonth() + 1 < 10 ? '0' + (dd.getMonth() + 1) : dd.getMonth() + 1; //获取当前月份的日期 

      var d = dd.getDate() < 10 ? '0' + dd.getDate() : dd.getDate();
      return y + "-" + m + "-" + d;
    },

    /* 获取场馆类型数据 */
    getShopVenuesTypeData: function (param) {
      var customIndex = getApp().globalData.AddClientUrl('/wx_get_shop_venues_types.html', {
        shopId: param.addShopId
      }); // wx.showLoading({
      //   title: 'loading'
      // })

      getApp().globalData.showToastLoading('loading', true);
      var that = this;
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log("=====shopVenuesTypeData======", res.data);
          let venuesTypeList = res.data.relateObj.result;
          that.setData({
            venuesTypeList: venuesTypeList
          });
          console.log("=====that.data.venuesTypeList======", that.venuesTypeList);

          if (venuesTypeList.length != 0) {
            let selectVenuesData = that.selectVenuesData;
            selectVenuesData.venuesTypeData = {
              index: 0,
              data: that.venuesTypeList[0]
            };
            selectVenuesData.venuesCelleData = {
              index: 0,
              data: that.venuesTypeList[0].venues[0]
            };
            that.setData({
              selectVenuesData: selectVenuesData
            });
            that.getNextSevenDays();
          }

          wx.hideLoading();
        },
        fail: function (res) {
          console.log("fail");
          wx.hideLoading();
          getApp().globalData.loadFail();
        },
        complete: function () {
          that.setData({
            canRefresh: true
          });
        }
      });
    },
    more_product_list_URLFun: function (params) {
      let resule = getApp().globalData.AddClientUrl("/more_product_list.html", params);
      return resule;
    },
    toProductDetail: function (event) {
      console.log("--------toProductDetail------");
      console.log(event.currentTarget.dataset.info);
      var info = event.currentTarget.dataset.info;
      wx.navigateTo({
        url: '../productDetail/index?id=' + info.id + "&addShopId=" + info.belongShopId
      });
    },

    /* 购物车加减 */
    postParams: function (data) {
      var that = this;
      var customIndex = getApp().globalData.AddClientUrl("/change_shopping_car_item.html", data, 'post');
      wx.request({
        url: customIndex.url,
        data: customIndex.params,
        header: getApp().globalData.headerPost,
        method: 'POST',
        success: function (res) {
          console.log(res.data);
          wx.hideLoading();
          that.setData({
            countGood: res.data.totalCarItemCount,
            countPrice: res.data.totalCarItemPrice,
            shopProList: that.shopProList
          });
          that.getCart();
        },
        fail: function (res) {
          wx.hideLoading();
          getApp().globalData.loadFail();
        }
      });
    },
    //items:[{productId:1,caratesianId:0,count:1}]
    createOrder: function () {
      if (!getApp().globalData.checkShopOpenTime()) {
        return;
      }

      if (!getApp().globalData.checkIfLogin()) {
        return;
      }

      console.log(this.pushItem);
      let pushItem = this.pushItem;
      let postParam = {
        postCarItemJson: {
          items: []
        }
      };

      for (let i = 0; i < pushItem.length; i++) {
        let item = {
          productId: '',
          caratesianId: '0',
          count: ''
        };
        item.productId = pushItem[i].id;

        if (!!pushItem[i].measureCartensian) {
          item.cartesianId = pushItem[i].measureCartensian.id;
        }

        postParam.shopId = pushItem[i].belongShopId;
        postParam.orderType = '0';
        item.count = pushItem[i].count_offline;
        postParam.postCarItemJson.items.push(item);
      }

      postParam.postCarItemJson = JSON.stringify(postParam.postCarItemJson);
      console.log(postParam);
      this.creatOrder_buyNowFun(postParam);
    },
    creatOrder_buyNowFun: function (data) {
      var customIndex = getApp().globalData.AddClientUrl("/buy_now.html", data, 'post');
      var that = this; // wx.showLoading({
      //   title: 'loading',
      //   mask: true
      // })

      getApp().globalData.showToastLoading('loading', true);
      wx.request({
        url: customIndex.url,
        data: customIndex.params,
        header: getApp().globalData.headerPost,
        method: 'POST',
        success: function (res) {
          wx.hideLoading();
          console.log(res);

          if (res.data.errcode == '10001') {
            getApp().globalData.checkIfLogin();
            return;
          }

          if (!!res.data.orderNo) {
            wx.navigateTo({
              url: '/pages/edit_order/index?orderNo=' + res.data.orderNo
            });
          } else {
            wx.showToast({
              title: res.data.errMsg,
              image: '/wxcomponents/images/icons/tip.png',
              duration: 2000
            });
          }
        },
        fail: function (res) {
          wx.hideLoading();
          getApp().globalData.loadFail();
        }
      });
    },

    /* 获取购物车 */
    getCart: function () {
      var customIndex = getApp().globalData.AddClientUrl("Client.User.CarItemList");
      var that = this; //拿custom_page

      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log(res.data);

          if (res.data.errcode == '10001') {
            that.setData({
              cart: []
            });
          } else {
            if (!!res.data.result.length) {
              that.setData({
                cart: res.data.result
              });
              that.showPrice();
            } else {
              that.setData({
                cart: []
              });
              that.setData({
                pushItem: []
              });
              that.setData({
                showType: false
              });
            }
          }
        },
        fail: function (res) {}
      });
    },
    //提交规格产品
    submitMeasure: function (id) {
      var that = this;
      let focusProduct = this.MeasureItem;
      let measurementJson = this.measurementJson;
      let data = {};
      data.cartesianId = measurementJson.id;
      data.productId = focusProduct.id;
      data.shopId = focusProduct.belongShopId;
      data.count = 1;
      data.type = 'add';
      var customIndex = getApp().globalData.AddClientUrl("/change_shopping_car_item.html", data, 'post');
      wx.request({
        url: customIndex.url,
        data: customIndex.params,
        header: getApp().globalData.headerPost,
        method: 'POST',
        success: function (res) {
          console.log('--------add----------');
          console.log(res.data);
          that.setData({
            showGuigeType: false
          });
          wx.hideLoading();
        },
        fail: function (res) {
          wx.hideLoading();
          getApp().globalData.loadFail();
        }
      });
    },
    //获取规格价格参数
    get_measure_cartesionFun: function () {
      console.log(this.MeasureItem);
      let productId = this.MeasureItem.id;
      let postStr = '';

      for (let i = 0; i < this.MeasureParams.length; i++) {
        postStr += this.MeasureParams[i].value + ',';
      }

      let param = {};
      param.productId = productId;
      param.measureIds = postStr;
      let customIndex = getApp().globalData.AddClientUrl("/get_measure_cartesion.html", param);
      var that = this;
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log(res.data);
          that.setData({
            measurementJson: res.data
          });
        },
        fail: function (res) {
          console.log("fail");
          getApp().globalData.loadFail();
        },
        complete: function () {}
      });
    },

    /* 初始化 选规格 */
    chooseMeasureItem: function (event) {
      let productData = this.shopProList;
      let index = event.currentTarget.dataset.id;
      let focusProduct = productData[index];

      for (let i = 0; i < focusProduct.measureTypes.length; i++) {
        focusProduct.measureTypes[i].checkedMeasureItem = 0; //初始化选择的数据

        let param = {};
        param.name = focusProduct.measureTypes[i].name;
        param.value = focusProduct.measureTypes[i].productAssignMeasure[0].id;
        this.MeasureParams.push(param);
      }

      this.setData({
        showGuigeType: true,
        MeasureItem: focusProduct
      });
      this.get_measure_cartesionFun();
    },
    //选择规格小巷的---显示
    radioChange: function (e) {
      let index = e.currentTarget.dataset.index;
      let indexJson = getApp().globalData.getSpaceStr(index, '-'); //console.log(indexJson)

      let focusItem = this.MeasureItem;
      focusItem.measureTypes[indexJson.str1].checkedMeasureItem = indexJson.str2;
      this.setData({
        MeasureItem: focusItem
      });
    },
    //选择规格小巷---获取数据
    chooseMeasure: function (e) {
      console.log(e.detail.value);
      let chooseMeasureJson = getApp().globalData.getSpaceStr(e.detail.value, '-');
      console.log(chooseMeasureJson);

      for (let i = 0; i < this.MeasureParams.length; i++) {
        if (this.MeasureParams[i].name == chooseMeasureJson.str1) {
          this.MeasureParams[i].value = chooseMeasureJson.str2;
        }
      }

      this.get_measure_cartesionFun();
    },
    closeGuigeZhezhao: function () {
      this.setData({
        showGuigeType: false
      });
      this.MeasureParams = [];
    },
    getParac: function (type) {
      var that = this;
      let customIndex;

      if (type == "index") {
        customIndex = getApp().globalData.AddClientUrl("/custom_page_shop.html", {}, 'get', '1');
      } else {
        customIndex = getApp().globalData.AddClientUrl("/custom_page_shop_" + this.params.belongShop + ".html", {}, 'get', '1');
      } //拿custom_page


      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log("====== res.data=========", res.data);
          wx.hideLoading();

          if (!res.data.errcode || res.data.errcode == '0') {
            if (type == "index") {
              that.setData({
                componentIndexState: true
              });
            } else {
              that.setData({
                componentState: true
              });
            }
          } else {
            console.log('加载失败');

            if (type == "index") {
              that.setData({
                componentIndexState: false
              });
            } else {
              that.setData({
                componentState: false
              });
            }
          }
        },
        fail: function (res) {
          console.log(res);
          wx.hideLoading();
          wx.showModal({
            title: '提示',
            content: '加载失败，点击【确定】重新加载',
            success: function (res) {
              if (res.confirm) {
                that.getParac();
              } else if (res.cancel) {
                getApp().globalData.toIndex();
              }
            }
          });
        }
      });
    },
    setCartInProduct: function () {
      console.log('====setCartInProduct.shopProList=====', this.shopProList);
      console.log('====setCartInProduct.pushItem=====', this.pushItem);
      let productData = this.shopProList;
      let pushItem = this.pushItem;

      if (productData != null) {
        for (let j = 0; j < productData.length; j++) {
          productData[j].inCarCount = 0;
        }

        for (let i = 0; i < pushItem.length; i++) {
          for (let j = 0; j < productData.length; j++) {
            if (pushItem[i].id == productData[j].id) {
              productData[j].inCarCount += pushItem[i].count_offline;
            }
          }
        }

        this.setData({
          shopProList: productData
        });
      }

      if (pushItem.length !== 0) {
        this.getPriceAndCount();
      }

      this.setAppCart();
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom2: function () {
      var that = this;
      console.log("=======bottom======", this.canRefresh);

      if (this.canRefresh) {
        this.setData({
          canRefresh: false
        });
        setTimeout(function () {
          if (that.listPage.totalSize > that.listPage.curPage * that.listPage.pageSize) {
            that.listPage.page++;
            that.params.page++;
            that.getShopListData(that.params);
          }
        }, 300);
      }
    },
    setData: function (obj) {
      let that = this;
      let keys = [];
      let val, data;
      Object.keys(obj).forEach(function (key) {
        keys = key.split('.');
        val = obj[key];
        data = that.$data;
        keys.forEach(function (key2, index) {
          if (index + 1 == keys.length) {
            that.$set(data, key2, val);
          } else {
            if (!data[key2]) {
              that.$set(data, key2, {});
            }
          }

          data = data[key2];
        });
      });
    }
  }
};
</script>
<style>
@import "./index.css";
</style>